package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.OrderDao;
import com.itheima.dao.OrderSettingDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Order;
import com.itheima.service.OrdersettinglistService;
import com.itheima.utils.SMSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service(interfaceClass = OrdersettinglistService.class)
@Transactional
public class OrdersettinglistServiceImpl implements OrdersettinglistService {

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private OrderSettingDao orderSettingDao;

    /**
     * 分页查询,条件查询预约信息
     * @param qpb
     * @return
     */
    @Override
    public PageResult findByPage(QueryPageBean qpb) {
        PageHelper.startPage(qpb.getCurrentPage(),qpb.getPageSize());
        Page<Order> page = orderDao.findByCondition1(qpb.getQueryString());
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 删除一条预约记录
     * @param order
     * @return
     */
    @Override
    public void delete(Order order) {
        orderDao.deleteById(order.getId());
        orderSettingDao.updateReservation(order.getOrderDate());
    }
}
